//
// Created by xili on 2024/9/23 17:10.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int maxOperations(vector<int> &nums, int k) {
        int ans = 0;
        unordered_map<int, int> cnt;
        for (int x: nums) {
            auto it = cnt.find(k - x);
            if (it != cnt.end() && it->second) {
                it->second--;
                ans++;
            } else {
                cnt[x]++;
            }
        }
        return ans;
    }
};
